package com.atguigu.yygh.orders.controller;

import com.atguigu.yygh.common.result.R;
import com.atguigu.yygh.model.order.OrderInfo;
import com.atguigu.yygh.orders.service.OrderInfoService;

import com.atguigu.yygh.vo.order.OrderCountQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 订单表 前端控制器
 * </p>
 *
 * @author atguigu
 */
@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderInfoController {

    @Autowired
    private OrderInfoService orderInfoService;



    //根据订单id查询订单详情
    @GetMapping("auth/getOrders/{orderId}")
    public R getOrders(@PathVariable Long orderId) {
        OrderInfo orderInfo = orderInfoService.getOrderById(orderId);
        return R.ok().data("orderInfo",orderInfo);
    }

    // 根据排班id 和 就诊人id 生成挂号订单
    // service里面根据id参数查询后远程调用医院模拟系统的接口生成订单，订单会返回到平台，平台将订单保存
    // 医院系统生成订单，平台得到订单并保存到mysql中
    @PostMapping("auth/submitOrder/{scheduleId}/{patientId}")
    public R submitOrder(@PathVariable String scheduleId,
            @PathVariable Long patientId) {

        long id = orderInfoService.generateOrder(scheduleId,patientId);

        return R.ok().data("orderId", id); // 只返回订单id，通过id重新查询mongodb,回显订单
    }

    //取消预约
    @GetMapping("auth/cancelOrder/{orderId}")
    public R cancelOrder(@PathVariable("orderId") Long orderId) {

        boolean flag = orderInfoService.cancelOrder(orderId);
        return R.ok().data("flag",flag);
    }

    //查询统计数据
    //条件：医院名称，时间范围
    //@ApiOperation("查询统计数据")
    @PostMapping("inner/getCountMap")
    public Map<String,Object> getCount(@RequestBody OrderCountQueryVo orderCountQueryVo) {
        Map<String,Object> result = orderInfoService.getCountMap(orderCountQueryVo);
        return result;
    }
}

